package com.song.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.song.service.SentinelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TonySong
 * @date 2024/5/9 0009
 * @time 14:56
 */
@RestController
@RequestMapping("/book")
public class OneController {

    @Value("${server.port}")
    private String port;

    @SentinelResource(fallbackClass = {SentinelController.class},fallback = "fallback1")
    @GetMapping("/")
    public String service1() {
        return this.port + "service1";
    }

    @Autowired
    private SentinelService service;

    @SentinelResource(fallbackClass = {SentinelController.class},fallback = "fallback2")
    @GetMapping("/server1")
    public String server1(){
        service.getUser();
        return "server1访问";
    }
    @SentinelResource(fallbackClass = {SentinelController.class},fallback = "fallback2")
    @GetMapping("/server2")
    public String server2(){
        service.getUser();
        return "server2访问";
    }
}
